home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / dosnos2.arc / CONVERS.ASM next >
Encoding:
Assembly Source File  |  1985-10-24  |  7.0 KB  |  301 lines

  1.     PAGE 60,132
  2.     TITLE    Conversion routines
  3.     SUBTTL    Called by file: dosknows.asm
  4.  
  5.  
  6. ;-----------------------------------------------------------------------;
  7. ; Convers.asm            June 1, 1985            Ver 1.0 ;
  8. ;                                    ;
  9. ;    this file contains the support routines to dosknows.asm        ;
  10. ;                                    ;
  11. ;    Anil Bharvaney                            ;
  12. ;    @fido 79                            ;
  13. ;    (212) 535-8924                            ;
  14. ;-----------------------------------------------------------------------;
  15.  
  16.  
  17.     SUBTTL    All public routines declared here
  18.     PAGE
  19.  
  20.  
  21.  
  22.     ;------------------------------------------------------------;
  23.     ; All public routines are named over here             ;
  24.     ;------------------------------------------------------------;
  25.  
  26.     PUBLIC    Stdin,Stdout,Strout,ToHEX,ToDec,ToDecW
  27.  
  28.  
  29.     SUBTTL all major equates
  30.     PAGE
  31.  
  32.  
  33.  
  34. ;      all major equates are here
  35.  
  36. DOS        EQU    21H
  37. INCHAR        EQU    01H
  38. OUTCHAR     EQU    02H
  39. OUTSTRING    EQU    09H
  40. TERMINATOR    EQU    '$'
  41. CR        EQU    13
  42. LF        EQU    10
  43.  
  44.  
  45.     SUBTTL    Data Segment
  46.     PAGE
  47.  
  48.  
  49.  
  50. DSEG    SEGMENT PUBLIC    PARA 'DATA'
  51.  
  52. ASCII    DB    '0123456789ABCDEF'
  53.  
  54. DSEG    ENDS
  55.  
  56.  
  57.  
  58.     SUBTTL    code segment
  59.     PAGE
  60.  
  61.  
  62. CSEG    SEGMENT PUBLIC PARA 'CODE'
  63.  
  64.     ASSUME    CS:CSEG,DS:DSEG
  65.  
  66.     SUBTTL PROCEDURE STDIN
  67.     PAGE
  68.  
  69.  
  70. ;------------------------------------------------------------------------------;
  71. ;      PROCEDURE: Stdin                                ;
  72. ;           Accepts input of one character.    Echos and waits.           ;
  73. ;      In:                                       ;
  74. ;           Nothing                                   ;
  75. ;      Out:                                       ;
  76. ;           Char received is in register AL                       ;
  77. ;------------------------------------------------------------------------------;
  78.  
  79. STDIN    PROC    NEAR
  80.  
  81.     MOV    AH,INCHAR        ;input w/ echo and wait of one char
  82.     INT    DOS            ;DOS call
  83.     RET
  84.  
  85. STDIN    ENDP
  86.  
  87.  
  88.  
  89.     SUBTTL    PROCEDURE STDOUT
  90.     PAGE
  91.  
  92.  
  93. ;------------------------------------------------------------------------------;
  94. ;      PROCEDURE: Stdout                               ;
  95. ;           Prints out one character to the console.                ;
  96. ;      In:                                       ;
  97. ;           AL character to print                           ;
  98. ;      Out:                                       ;
  99. ;           Nothing.                                ;
  100. ;------------------------------------------------------------------------------;
  101.  
  102. STDOUT           PROC    NEAR
  103.  
  104.     PUSH    DX        ;save register
  105.     PUSH    AX
  106.  
  107.     MOV    DL,AL        ;mov character
  108.     MOV    AH,OUTCHAR    ;output character in AL to Console
  109.     INT    DOS        ;Dos call
  110.  
  111.     POP    AX        ;restore user register
  112.     POP    DX        ;restore user register
  113.     RET
  114.  
  115. STDOUT    ENDP
  116.  
  117.  
  118.     SUBTTL PROCEDURE STROUT
  119.     PAGE
  120.  
  121.  
  122. ;------------------------------------------------------------------------------;
  123. ;      PROCEDURE: Strout                               ;
  124. ;           Prints out one string terminated by $.                   ;
  125. ;      In:                                       ;
  126. ;           DS:DX points to the string to be printed to the console           ;
  127. ;      Out:                                       ;
  128. ;           Nothing.                                ;
  129. ;------------------------------------------------------------------------------;
  130.  
  131. STROUT           PROC  NEAR
  132.  
  133.     PUSH    DX            ;save caller's registers
  134.     PUSH    AX            
  135.  
  136.     MOV    AH,Outstring        ;func to write $ terminated string
  137.     INT    DOS
  138.     
  139.     POP    AX            ;restore caller registers
  140.     POP    DX
  141.     RET
  142.  
  143. STROUT    ENDP
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.     SUBTTL PROCEDURE TOHEX
  151.     PAGE
  152.  
  153.  
  154.  
  155. ;------------------------------------------------------------------------------;
  156. ;      PROCEDURE: TOHEX                                ;
  157. ;           Converts Word to Ascii Hexadecimal and displays it on the screen;
  158. ;      In:                                       ;
  159. ;           DX has binary number to be converted                   ;
  160. ;      Out:                                       ;
  161. ;           Nothing.  Output goes to console                    ;
  162. ;------------------------------------------------------------------------------;
  163.  
  164. TOHEX           PROC    NEAR
  165.  
  166.     PUSH    AX        ;save registers used
  167.     PUSH    BX
  168.     PUSH    CX
  169.  
  170.     LEA    BX,ASCII    ;translate table address
  171.     MOV    CX,4        ;four nibbles to a word, (need 4 hex chars)
  172. More:
  173.     PUSH    CX        ;save this
  174.     MOV    CL,4        ;move nibble msb to lsb
  175.     ROL    DX,CL        ;moves upper nibble to lsb's lower nibble
  176.     MOV    AL,DL        ;move rotated in nibble to al
  177.     AND    AL,0FH        ;don't need the upper nibble
  178.     XLAT    ASCII        ;translate it to Hex
  179.     CALL    Stdout        ;prints char in AL
  180.     POP    CX        ;restore the count
  181.     LOOP    More        ;do the other nibbles..
  182.  
  183.     POP    CX        ;restore user registers
  184.     POP    BX
  185.     POP    AX
  186.     RET
  187.  
  188. TOHEX    ENDP
  189.  
  190.  
  191.  
  192.  
  193.     SUBTTL PROCEDURE TO DECIMAL (BYTE)
  194.     PAGE
  195.  
  196.  
  197. ;------------------------------------------------------------------------------;
  198. ;      PROCEDURE: TODEC                                ;
  199. ;           Converts BYTE to Ascii Decimal      and displays it on the screen;
  200. ;      In:                                       ;
  201. ;           DL has binary number to be converted                   ;
  202. ;      Out:                                       ;
  203. ;           Nothing.  Output goes to console                    ;
  204. ;------------------------------------------------------------------------------;
  205.  
  206. TODEC    PROC    NEAR
  207.  
  208.     PUSH    AX    ;Save registers used in routine
  209.     PUSH    CX
  210.  
  211.     XOR    AH,AH
  212.     MOV    AL,DL    ;Get the byte to be converted
  213.     XOR    CL,CL    ;Counts # of words stuffed onto stack
  214. LP:
  215.     AAM        ;AL/10 remainder in AL, quotient in AH
  216.     ADD    AL,'0'  ;make it ascii
  217.     MOV    CH,AH    ;save it for later
  218.     XOR    AH,AH    ;getting ready for pushing onto stack
  219.     PUSH    AX    ;save it onto stack
  220.     MOV    AL,CH    ;restore the number
  221.     INC    CL    ;increment count of words on stack
  222.     CMP    AX,0    ;Are we done?
  223.     JE    PRTIT    ; if done, print it out
  224.     JMP    LP    ;continue conversion
  225.  
  226. PRTIT:            ;done converting
  227.     CMP    CL,0    ;anything to left to pop up and print?
  228.     JE    DONE    ; if nothing left, bye
  229.     POP    AX    ;pop up the number
  230.     DEC    CL    ;decrease count of words on stack
  231.     CALL    Stdout    ;print the ascii character in AL
  232.     JMP    Prtit    ;while more characters to print, print
  233.  
  234. DONE:
  235.     POP    CX    ;restore callers registers
  236.     POP    AX
  237.     RET
  238.  
  239.  
  240. TODEC    ENDP
  241.  
  242.  
  243.     SUBTTL    PROCEDURE TO DECIMAL (WORD)
  244.     PAGE
  245.  
  246.  
  247. ;------------------------------------------------------------------------------;
  248. ;      PROCEDURE: TODECW                               ;
  249. ;           Converts WORD to Ascii Decimal      and displays it on the screen;
  250. ;      In:                                       ;
  251. ;           DX has binary number to be converted                   ;
  252. ;      Out:                                       ;
  253. ;           Nothing.  Output goes to console                    ;
  254. ;------------------------------------------------------------------------------;
  255.  
  256. TODECW    PROC    NEAR
  257.  
  258.     PUSH    AX        ;save caller's registers
  259.     PUSH    BX
  260.     PUSH    CX
  261.     PUSH    DX
  262.  
  263.     MOV    AX,DX        ;get ready to divide dx:ax
  264.     MOV    BX,10        ;divide by 10
  265.     XOR    CX,CX        ;Initialize counter
  266.  
  267. LPW:
  268.     XOR    DX,DX        ;top word is zero
  269.     DIV    BX        ;remainder is in dx, ax has quotient
  270.     ADD    DL,'0'          ;adjust remainder to be ascii
  271.     PUSH    DX        ;save it, last one to be printed
  272.     INC    CX        ;increment counter
  273.     CMP    AX,09        ;are we done yet
  274.     JA    LPW        ; if not done, repeat it again
  275.  
  276.     ADD    AL,'0'          ;the most significant character is here
  277.     CALL    Stdout
  278.  
  279.  
  280. WPRTIT:         ;done converting
  281.     CMP    CX,0    ;anything to left to pop up and print?
  282.     JE    WDONE    ; if nothing left, bye
  283.     POP    AX    ;pop up the number
  284.     DEC    CX    ;decrease count of words on stack
  285.     CALL    Stdout    ;print the ascii character in AL
  286.     JMP    WPrtit    ;while more characters to print, print
  287.  
  288. WDONE:
  289.     POP    DX        ;restore caller's registers
  290.     POP    CX
  291.     POP    BX
  292.     POP    AX
  293.  
  294.     RET
  295.  
  296. TODECW    ENDP
  297.  
  298.  
  299. CSEG   ENDS
  300.        END
  301.